//
//  inputViewController.m
//  11-30
//
//  Created by Mac OS on 15-12-7.
//  Copyright (c) 2015年 12-03. All rights reserved.
//

#import "inputViewController.h"
#import "ViewController.h"
@interface myItem : NSObject <UIActivityItemSource>

@property (strong,nonatomic) NSString * text;


@end

@implementation myItem

- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController{
    return self.text;
}

- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType{
    return self.text;
}

@end

@interface inputViewController ()<UITextFieldDelegate,Keep,UIActivityItemSource>
{
    UITextField *tfName;
    UITextField *tfTel;
}
@end

@implementation inputViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    tfName = [[UITextField alloc]initWithFrame:CGRectMake(16, 15, self.view.frame.size.width, 44)];
    tfTel = [[UITextField alloc]initWithFrame:CGRectMake(16, 15, self.view.frame.size.width, 44)];
    tfName.text = self.name;
    tfTel.text = self.tel;
    
    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(onItem:)];
    UIBarButtonItem *item2 = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(save:)];
    self.navigationItem.rightBarButtonItems = @[item1,item2];
}

- (void)onItem:(UIBarButtonItem *)sender{
    myItem * item = [myItem new];
    item.text = @"尹彬爱你";
    UIActivityViewController * con = [[UIActivityViewController alloc]initWithActivityItems:@[item] applicationActivities:nil];
    [self presentViewController:con animated:YES completion:nil];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    [cell addSubview:indexPath.section == 0 ? tfName : tfTel];
    
    return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return @[@"姓名：",@"电话："][section];
}

-(void)save:(UIBarButtonItem *)barbut{
    [self.delegate keepFinishedWithName:tfName.text tel:tfTel.text];
    [self.navigationController popToViewController:self animated:YES];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
